"""
@File    :   custom_field.py
@Time    :   2024/03/26 15:33:32
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   全局的自定义验证字段
"""

from pydantic import EmailStr
from pydantic.networks import validate_email
from pydantic_core import PydanticCustomError


class CustomErrorMsgEmailStr(EmailStr):
    """自定义错误信息的EmailStr"""

    @classmethod
    def _validate(cls, __input_value: str) -> str:
        try:
            return validate_email(__input_value)[1]
        except PydanticCustomError:
            raise PydanticCustomError(
                "custom_email_value_error",
                "邮箱格式错误",
            )
